import { defineStore } from 'pinia'
import { getThings,deleteThings,updateThings,addThings } from '../utils/api';
export const useThingsStore = defineStore('store',{
  state:() => {
    return {
      todoList:[],
      finishList:[]
    }
  },
  actions:{
    async updateList(){
      let res = await getThings(1,0)// 这里写死，用户id为1，未完成
      this.todoList = res.data.data
      res = await getThings(1,1)// 这里写死，用户id为1，未完成
      this.finishList = res.data.data
    },
    async changeList(id,finish){
      let res = await updateThings(id,finish)
      await this.updateList()
    },
    async deleteList(id){
      let res = await deleteThings(id)
      await this.updateList()
    },
    async addList(content,userid){
      let res = await addThings(content,userid)
      await this.updateList()
    }
  }
})